--- ========================================================= ---
---  Setup Revision, Version, Date and add to AceLibrary
--- ========================================================= ---
local VERSION = tonumber(("$Revision: 52619 $"):match("%d+"))

local DaHud = DaHud
DaHud_Module_Text = DaHud:NewModule("Module_Text", "AceEvent-2.0")
local self = DaHud_Icon
if DaHud.revision < VERSION then
	DaHud.version = "r" .. VERSION
	DaHud.revision = VERSION
	DaHud.date = ("$Date: 2007-10-19 21:07:04 -0400 (Fri, 19 Oct 2007) $"):match("%d%d%d%d%-%d%d%-%d%d")
end
DaHud.desc = "Text Module"

--- ========================================================= ---
---  Setup Locals
--- ========================================================= ---
local DogTag = AceLibrary("DogTag-1.0")
local Media = AceLibrary("SharedMedia-1.0")

local L = DaHud:L("DaHud_Module_Text")

local fontslist = {}

local defaultStyle = {
	name = "Standard",
	class = "Standard",
	guild = "Standard",
	range = "Standard",
	health = "Smart",
	power = "Smart",
	threat = "Percent",
	experience = "Smart",
	reputation = "Smart",
	custom = "none",
	none = "none",
	casting = "Smart",
	sunders = "Smart",
}

local textStyles = {
	name = {
		["Standard"]			= "[Name] [AFKDND:Angle]",
		["Hostility Colored"]	= "[Name:HostileColor] [AFKDND:Angle]",
		["Class Colored"]		= "[Name:ClassColor] [AFKDND:Angle]",
		["Long"]				= "[Level:DifficultyColor:Bracket] [Name:ClassColor] [AFKDND:Angle]",
		["Long w/ Class"]		= "[Level:DifficultyColor:Bracket] [SmartClass:ClassColor:Bracket] [Name:ClassColor] [AFKDND:Angle]",
		["Long w/ Race/Class"]	= "[Level:DifficultyColor:Bracket] [SmartRace:Bracket] [SmartClass:ClassColor:Bracket] [Name:ClassColor] [AFKDND:Angle]",
		["Long w/ Druid form"]	= "[Level:DifficultyColor:Bracket] [Name:ClassColor] [DruidForm:Paren] [AFKDND:Angle]",
	},
	class = {
		["Standard"]			= "[Classification] [SmartRace:Bracket] [SmartClass:ClassColor] [DruidForm:Paren]",
		["Player Classes Only"]	= "[Classification] [SmartRace:Bracket] [PlayerClass:ClassColor] [DruidForm:Paren]",
		["Short"]				= "[DifficultyColor][Plus][White] [SmartRace]",
	},
	guild = {
		["Standard"]			= "[Guild:Angle]",
	},
	range = {
		["Standard"]			= "[Text(Range:):Gray] [Range?Text([Range]):Gray:Bracket][~Range?Text(28+):Gray:Bracket] [Text(yds):Gray]",
	},
	combos = {
		["Standard"]			= "[Combos:HideZero?Text([Combos])]",
	},
	health = {
		["Absolute"]			= "[SureHP:HPColor:PercentHP:Percent:HPColor]",
		["Absolute Short"]		= "[SureHP:HPColor:Short:PercentHP:Percent:HPColor]",
		["Difference"]			= "[SmartMissingHP:Color(ff7f7f)]",
		["Percent"]				= "[PercentHP:Percent:HPColor]",
		["Mini"]				= "[CurHP:VeryShort:HPColor]",
		["Smart"] 				= "[CurHP:~IsLessEqual(1)?Text([CurHP:Short:HPColor] / [MaxHP:Short:HPColor] [PercentHP:Percent:Paren])!Status]",
		["Absolute and Percent"]= "[CurHP:Short:HPColor] / [MaxHP:Short:HPColor] [PercentHP:Percent:Paren]",
		["Informational"]		= "[IsFriend?~Status?MissingHP:HideZero:Short:Color(ff7f7f)] || [CurHP:Short:HPColor] / [MaxHP:Short:HPColor] [PercentHP:Percent:Paren]"
	},
	power = {
		["Absolute"]			= "[~HasNoMP?FractionalMP:PowerColor]",
		["Absolute Short"]		= "[~HasNoMP?FractionalMP:Short:PowerColor]",
		["Difference"]			= "[MissingMP:HideZero:Negate:PowerColor]",
		["Percent"]				= "[PercentMP:Percent:PowerColor]",
		["Mini"]				= "[~HasNoMP?CurMP:VeryShort:PowerColor]",
		["Smart"]				= "[CurMP:HideZero?Text([CurMP:Short:PowerColor] / [MaxMP:Short:PowerColor] [PercentMP:Percent:Paren])]",
	},
	threat = {
		["Absolute"]			= "[~HasNoThreat?Threat:Color(ff7f7f)]",
		["Absolute Short"]		= "[~HasNoThreat?Threat:Short:Color(ff7f7f)]",
		["Fractional"]			= "[~HasNoThreat?FractionalThreat:Color(ff7f7f)]",
		["Fractional Short"]	= "[~HasNoThreat?FractionalThreat:Short:Color(ff7f7f)]",
		["Difference"]			= "[~HasNoThreat?MissingThreat:Negate:Color(ff7f7f)]",
		["Percent"]				= "[~HasNoThreat?PercentThreat:Percent:Color(ff7f7f)]",
		["Mini"]				= "[~HasNoThreat?Threat:VeryShort:Color(ff7f7f)]",
		["Smart"]				= "[Threat:HideZero?Text([Threat:Short:Color(ff7f7f)] / [MaxThreat:Short:Color(ff7f7f)] [PercentThreat:Percent:Paren])]",
	},
	experience = {
		["Absolute"]			= "[FractionalXP:Fuchsia]",
		["Absolute Short"]		= "[FractionalXP:Short:Fuchsia]",
		["Difference"]			= "[MissingXP:Fuchsia]",
		["Percent"]				= "[PercentXP:Percent:Fuchsia]",
		["Smart"]				= "[CurXP:Short:Fuchsia] / [MaxXP:Short:Fuchsia] [PercentXP:Percent:Paren]",
		["Informational"]		= "[CurXP:HideZero?Text([CurXP:Short:Fuchsia] / [MaxXP:Short:Fuchsia] [PercentXP:Percent:Paren])] [RestXP:HideZero?Text([RestXP:Short] [PercentRestXP:Percent:Paren]):Cyan:Bracket]",
	},
	reputation = {
		["Absolute"]			= "[FractionalRep:Cyan]",
		["Absolute Short"]		= "[FractionalRep:Short:Cyan]",
		["Difference"]			= "[MissingRep:Cyan]",
		["Percent"]				= "[PercentRep:Cyan]",
		["Smart"]				= "[CurRep:HideZero?Text([CurRep:Short:Cyan] / [MaxRep:Short:Cyan] [PercentRep:Percent:Paren])]",
	},
	casting = {
		["Smart"]				= "Smart",
	},
	sunders = {
		["Smart"]				= "Smart",
	},
}

--- ========================================================= ---
---  On Intitalize / Setup Database
--- ========================================================= ---
function DaHud_Module_Text:OnInitialize()
	self.db = DaHud:AcquireDBNamespace("Module_Text")
	DaHud:RegisterDefaults("Module_Text", "profile", {
		number = 25,
		hudtext1 = {"Player Health", true, "LOW", 1, 150, 20, 1, "center", -150, -180, "player", "health", "Smart", "[CurHP:~IsLessEqual(1)?Text([CurHP:Short:HPColor] / [MaxHP:Short:HPColor] [PercentHP:Percent:Paren])!Status]", "Default", 14, "OUTLINE", false, false, "never"},
		hudtext2 = {"Player Mana", true, "LOW", 1, 150, 20, 1, "center", -150, -195, "player", "power", "Smart", "[CurMP:HideZero?Text([CurMP:Short:PowerColor] / [MaxMP:Short:PowerColor] [PercentMP:Percent:Paren])]", "Default", 14, "OUTLINE", false, false, "never"},
		hudtext3 = {"Target Health", true, "LOW", 1, 150, 20, 1, "center", 150, -180, "target", "health", "", "[CurHP:~IsLessEqual(1)?Text([CurHP:Short:HPColor] / [MaxHP:Short:HPColor] [PercentHP:Percent:Paren])!Status]", "Default", 14, "OUTLINE", false, false, "never"},
		hudtext4 = {"Target Mana", true, "LOW", 1, 150, 20, 1, "center", 150, -195, "target", "power", "", "[CurMP:HideZero?Text([CurMP:Short:PowerColor] / [MaxMP:Short:PowerColor] [PercentMP:Percent:Paren])]", "Default", 14, "OUTLINE", false, false, "never"},
		hudtext5 = {"Pet Health", true, "LOW", 1, 40, 20, 1, "left", -123, -155, "pet", "health", "Percent", "[PercentHP:Percent:HPColor]", "Default", 12, "OUTLINE", false, false, "never"},
		hudtext6 = {"Pet Mana", true, "LOW", 1, 40, 20, 1, "left", -123, -167, "pet", "power", "Percent", "[PercentMP:Percent:PowerColor]", "Default", 12, "OUTLINE", false, false, "never"},
		hudtext7 = {"Target of Target Health", true, "LOW", 1, 40, 20, 1, "right", 123, -155, "targettarget", "health", "Percent", "[PercentHP:Percent:HPColor]", "Default", 12, "OUTLINE", false, false, "never"},
		hudtext8 = {"Target of Target Mana", true, "LOW", 1, 40, 20, 1, "right", 123, -167, "targettarget", "power", "Percent", "[PercentMP:Percent:PowerColor]", "Default", 12, "OUTLINE", false, false, "never"},
		hudtext9 = {"Player Experience", true, "LOW", 1, 50, 20, 1, "center", -210, -135, "player", "experience", "Percent", "[PercentXP:Percent:Fuchsia]", "Default", 14, "OUTLINE", false, false, "never"},
		hudtext10 = {"Focus Health", true, "LOW", 1, 50, 20, 1, "center", 210, -160, "focus", "health", "Percent", "[PercentHP:Percent:HPColor]", "Default", 12, "OUTLINE", false, false, "never"},
		hudtext11 = {"Player Casting", true, "LOW", 1, 180, 20, 1, "left", -165, 135, "player", "casting", "Smart", "Smart", "Default", 12, "OUTLINE", false, false, "never"},
		hudtext12 = {"Target Casting", true, "LOW", 1, 180, 20, 1, "right", 165, 135, "target", "casting", "Smart", "Smart", "Default", 12, "OUTLINE", false, false, "never"},
		hudtext13 = {"Target Name", true, "LOW", 1, 250, 20, 1, "center", 0, -220, "target", "name", "Long", "[Level:DifficultyColor:Bracket] [Name:ClassColor] [AFKDND:Angle]", "Default", 14, "OUTLINE", false, false, "never"},
		hudtext14 = {"Target Class", true, "LOW", 1, 250, 20, 1, "center", 0, -235, "target", "class", "Standard", "[Classification] [SmartRace:Bracket] [SmartClass:ClassColor] [DruidForm:Paren]", "Default", 14, "OUTLINE", false, false, "never"},
		hudtext15 = {"Target Guild", true, "LOW", 1, 250, 20, 1, "center", 0, -205, "target", "guild", "Standard", "[Guild:Angle]", "Default", 14, "OUTLINE", false, false, "never"},
		hudtext16 = {"Target Range", true, "LOW", 1, 250, 20, 1, "center", 0, -190, "target", "range", "Standard", "[Text(Range:):Gray] [Range?Text([Range]):Gray:Bracket][~Range?Text(28+):Gray:Bracket] [Text(yds):Gray]", "Default", 14, "OUTLINE", false, false, "never"},
		hudtext17 = {"Target Combo Points", true, "LOW", 1, 20, 20, 1, "center", 185, 90, "target", "combos", "Standard", "[Combos:HideZero?Text([Combos])]", "Default", 16, "OUTLINE", false, false, "never"},
		hudtext18 = {"Target Sunders", false, "LOW", 1, 20, 20, 1, "center", 185, 90, "target", "sunders", "Smart", "Smart", "Default", 16, "OUTLINE", false, false, "never"},
		hudtext19 = {"Blank", false, "LOW", 1, 150, 20, 1, "center", -150, -180, "player", "health", "Smart", "[CurHP:~IsLessEqual(1)?Text([CurHP:Short:HPColor] / [MaxHP:Short:HPColor] [PercentHP:Percent:Paren])!Status]", "Default", 14, "OUTLINE", false, false, "never"},
		hudtext20 = {"Blank", false, "LOW", 1, 150, 20, 1, "center", -150, -180, "player", "health", "Smart", "[CurHP:~IsLessEqual(1)?Text([CurHP:Short:HPColor] / [MaxHP:Short:HPColor] [PercentHP:Percent:Paren])!Status]", "Default", 14, "OUTLINE", false, false, "never"},
		hudtext21 = {"Blank", false, "LOW", 1, 150, 20, 1, "center", -150, -180, "player", "health", "Smart", "[CurHP:~IsLessEqual(1)?Text([CurHP:Short:HPColor] / [MaxHP:Short:HPColor] [PercentHP:Percent:Paren])!Status]", "Default", 14, "OUTLINE", false, false, "never"},
		hudtext22 = {"Blank", false, "LOW", 1, 150, 20, 1, "center", -150, -180, "player", "health", "Smart", "[CurHP:~IsLessEqual(1)?Text([CurHP:Short:HPColor] / [MaxHP:Short:HPColor] [PercentHP:Percent:Paren])!Status]", "Default", 14, "OUTLINE", false, false, "never"},
		hudtext23 = {"Blank", false, "LOW", 1, 150, 20, 1, "center", -150, -180, "player", "health", "Smart", "[CurHP:~IsLessEqual(1)?Text([CurHP:Short:HPColor] / [MaxHP:Short:HPColor] [PercentHP:Percent:Paren])!Status]", "Default", 14, "OUTLINE", false, false, "never"},
		hudtext24 = {"Blank", false, "LOW", 1, 150, 20, 1, "center", -150, -180, "player", "health", "Smart", "[CurHP:~IsLessEqual(1)?Text([CurHP:Short:HPColor] / [MaxHP:Short:HPColor] [PercentHP:Percent:Paren])!Status]", "Default", 14, "OUTLINE", false, false, "never"},
		hudtext25 = {"Blank", false, "LOW", 1, 150, 20, 1, "center", -150, -180, "player", "health", "Smart", "[CurHP:~IsLessEqual(1)?Text([CurHP:Short:HPColor] / [MaxHP:Short:HPColor] [PercentHP:Percent:Paren])!Status]", "Default", 14, "OUTLINE", false, false, "never"},
	})
end

--- ========================================================= ---
---  On Enable
--- ========================================================= ---
function DaHud_Module_Text:OnEnable()
	self:SetupOptions()
	self:CreateFrames()
	self:UpdateAllFrames()
	
	self:BuildFontList()
	self:RegisterEvent("SharedMedia_Registered")
	
	self:RegisterEvent("DaHud_SetConfigMode")
	self:RegisterEvent("DaHud_ReloadAllFrames")	
	
	self:ScheduleRepeatingEvent("DaHud_Text_ProcessAllFrames", self.ProcessAllFrames, 0.05, self)
end

--- ========================================================= ---
---  On Disable
--- ========================================================= ---
function DaHud_Module_Text:OnDisable()
	self:UnregisterAllEvents();
end

--- ========================================================= ---
---  DaHud_SetConfigMode
--- ========================================================= ---
function DaHud_Module_Text:DaHud_SetConfigMode()
	self:UpdateAllFrames()
end

--- ========================================================= ---
---  DaHud_ReloadAllFrames
--- ========================================================= ---
function DaHud_Module_Text:DaHud_ReloadAllFrames()
	self:SetupOptions()
	self:UpdateAllFrames()
end

--- ========================================================= ---
---  Format Time
--- ========================================================= ---
function DaHud_Module_Text:FormatTime(time)
	if(time > 60 or self.TimerSet) then
		local minutes = math.floor((time / 60));
		local seconds = math.ceil(time - (60 * minutes));
		if (seconds == 60) then
			minutes = minutes + 1;
			seconds = 0;
		end
		if(strlen(seconds) < 2) then
			seconds =  "0"..seconds;
		end
		self.TimerSet = 1;
		return format("%s:%s", minutes, seconds);
	else
		return string.format( "%.1f", time);
	end
end

--- ========================================================= ---
---  SharedMedia_Registered
--- ========================================================= ---
function DaHud_Module_Text:SharedMedia_Registered(mediatype, name)
    if mediatype == Media.MediaType.FONT then
        self:BuildFontList()
    end
end

--- ========================================================= ---
---  Build Font List
--- ========================================================= ---
function DaHud_Module_Text:BuildFontList()
    for i,v in ipairs(fontslist) do
        fontslist[i] = nil
    end
    
    for k,v in pairs(Media:List(Media.MediaType.FONT)) do
        table.insert(fontslist, v)
    end
end

--- ========================================================= ---
---  Get Style Validate
--- ========================================================= ---
function DaHud_Module_Text:getStyleValidate(frame)
	local name, show, framestrata, framelevel, width, height, scale, align, posx, posy, unit, type, style, custom, font, size, outline, monochrome, button, tooltip = unpack(self.db.profile[frame])
	local styleValidates = {}
	local styles = textStyles[type]
	
	local t = {}
	local u = {}
	
	if styles then
		for k, v in pairs(styles) do
			t[k] = L[k]
			u[k] = v
		end
	end
	return t
end

--- ========================================================= ---
---  Get Style ValidateDesc
--- ========================================================= ---
function DaHud_Module_Text:getStyleValidateDesc(frame)
	local name, show, framestrata, framelevel, width, height, scale, align, posx, posy, unit, type, style, custom, font, size, outline, monochrome, button, tooltip = unpack(self.db.profile[frame])
	local styleValidates = {}
	local styles = textStyles[type]
	
	local t = {}
	local u = {}
	
	if styles then
		for k, v in pairs(styles) do
			t[k] = L[k]
			u[k] = v
		end
	end
	return u
end

--- ========================================================= ---
---  Setup Validates for Options
--- ========================================================= ---
local strataValidate = {
	BACKGROUND = L["Background"],
	LOW = L["Low"],
	MEDIUM = L["Medium"],
	HIGH = L["High"],
	DIALOG = L["Dialog"],
	TOOLTIP = L["Tooltip"],
}

local strataValidateDesc = {}

local alignValidate = {
	left = L["Left"],
	center = L["Center"],
	right = L["Right"],
}

local alignValidateDesc = {}

local eventTypeValidate = {
	name = L["Name"],
	class = L["Class"],
	guild = L["Guild"],	
	range = L["Range"],
	combos = L["Combo Points"],
	health = L["Health"],
	power = L["Power"],
	threat = L["Threat"],
	experience = L["Experience"],
	reputation = L["Reputation"],
	custom = L["Custom"],
	none = L["None"],
	casting = L["Casting"],
	sunders = L["Sunders"],
}

local eventTypeValidateDesc = {}

local eventUnitValidate = {
	player = L["Player"],
	target = L["Target"],
	focus = L["Focus"],
	pet = L["Pet"],
	targettarget = L["Target of Target"],
	targettargettarget = L["ToT of Target"],
}

local eventUnitValidateDesc = {}

local outlineValidate = {
	NONE = L["None"],
	OUTLINE = L["Outline"],
	THICKOUTLINE = L["Thick Outline"],
}

local outlineValidateDesc = {}

local tooltipValidate = {
	always = L["Always"],
	never = L["Never"],
	ooc = L["Out of Combat"],
}

local tooltipValidateDesc = {}

--- ========================================================= ---
---  Setup Options
--- ========================================================= ---
function DaHud_Module_Text:SetupOptions()
	DaHud.options.args.textframes = {
		name = L["Text Frames"],
		desc = L["Change the Text Frame options."],
		type = 'group',
		args = {
		},
	}

	for i=1, self.db.profile.number do
		local frame = "hudtext"..i
			
		self:UpdateMainOption(frame)
		self:UpdateNameOption(frame)
		self:UpdateShowOption(frame)
		self:UpdateFramestrataOption(frame)
		self:UpdateFramelevelOption(frame)
		self:UpdateWidthOption(frame)
		self:UpdateHeightOption(frame)
		self:UpdateScaleOption(frame)
		self:UpdateAlignOption(frame)
		self:UpdatePosXOption(frame)
		self:UpdatePosYOption(frame)
		self:UpdateUnitOption(frame)
		self:UpdateTypeOption(frame)
		self:UpdateStyleOption(frame)
		self:UpdateCustomOption(frame)
		self:UpdateFontOption(frame)
		self:UpdateSizeOption(frame)
		self:UpdateOutlineOption(frame)
		self:UpdateMonochromeOption(frame)
		self:UpdateButtonOption(frame)
		self:UpdateTooltipOption(frame)
	end
	
	self:UpdateGlobalOption(frame)
end

--- ========================================================= ---
---  Update Main Option
--- ========================================================= ---
function DaHud_Module_Text:UpdateMainOption(frame)
	local name, show, framestrata, framelevel, width, height, scale, align, posx, posy, unit, type, style, custom, font, size, outline, monochrome, button, tooltip = unpack(self.db.profile[frame])

	DaHud.options.args.textframes.args[frame] = {
		name = name,
		desc = L["Change the Text Frame options."],
		type = 'group',
		args = {
		}
	}
end

--- ========================================================= ---
---  Update Name Option
--- ========================================================= ---
function DaHud_Module_Text:UpdateNameOption(frame)
	DaHud.options.args.textframes.args[frame].args.name = {
		name = L["Name"],
		desc = L["Name the Frame."],
		type = 'text',
		usage = "<name>",
		get = function()
			local name, show, framestrata, framelevel, width, height, scale, align, posx, posy, unit, type, style, custom, font, size, outline, monochrome, button, tooltip = unpack(self.db.profile[frame])
			return name
		end,
		set = function(value) 
			self:SaveOptions(frame, "name", value)
			self:SetupOptions()
		end,
	}
end

--- ========================================================= ---
---  Update Show Option
--- ========================================================= ---
function DaHud_Module_Text:UpdateShowOption(frame)
	DaHud.options.args.textframes.args[frame].args.show = {
		name = L["Show"],
		desc = L["Show this Frame."],
		type = 'toggle',
		get = function()
			local name, show, framestrata, framelevel, width, height, scale, align, posx, posy, unit, type, style, custom, font, size, outline, monochrome, button, tooltip = unpack(self.db.profile[frame])
			return show
		end,
		set = function()
			local name, show, framestrata, framelevel, width, height, scale, align, posx, posy, unit, type, style, custom, font, size, outline, monochrome, button, tooltip = unpack(self.db.profile[frame])
			self:SaveOptions(frame, "show", not(show))
			self:UpdateAllFrames()
		end,
	}
end

--- ========================================================= ---
---  Update Framestrata Option
--- ========================================================= ---
function DaHud_Module_Text:UpdateFramestrataOption(frame)
	DaHud.options.args.textframes.args[frame].args.framestrata = {
		name = L["Frame Strata"],
		desc = L["Choose the layer the portrait is drawn on."],
		type = 'text',
		validate = strataValidate,
		validateDesc = strataValidateDesc,
		get = function()
			local name, show, framestrata, framelevel, width, height, scale, align, posx, posy, unit, type, style, custom, font, size, outline, monochrome, button, tooltip = unpack(self.db.profile[frame])
			return framestrata
		end,
		set = function(value) 
			self:SaveOptions(frame, "framestrata", value)
			self:UpdateAllFrames()
		end,
	}
end

--- ========================================================= ---
---  Update Framelevel Option
--- ========================================================= ---
function DaHud_Module_Text:UpdateFramelevelOption(frame)
	DaHud.options.args.textframes.args[frame].args.framelevel = {
		name = L["Frame Level"],
		desc = L["Change the Frame Level it is drawn on."],
		type = 'range',
		min = 1,
		max = 12,
		step = 1,
		bigStep = 2,
		get = function()
			local name, show, framestrata, framelevel, width, height, scale, align, posx, posy, unit, type, style, custom, font, size, outline, monochrome, button, tooltip = unpack(self.db.profile[frame])
			return framelevel
		end,
		set = function(value) 
			self:SaveOptions(frame, "framelevel", value)
			self:UpdateAllFrames()
		end,
	}
end

--- ========================================================= ---
---  Update Width Option
--- ========================================================= ---
function DaHud_Module_Text:UpdateWidthOption(frame)
	DaHud.options.args.textframes.args[frame].args.width = {
		name = L["Width"],
		desc = L["Change the Width."],
		type = 'range',
		min = 0,
		max = 500,
		step = 1,
		bigStep = 20,
		get = function()
			local name, show, framestrata, framelevel, width, height, scale, align, posx, posy, unit, type, style, custom, font, size, outline, monochrome, button, tooltip = unpack(self.db.profile[frame])
			return width
		end,
		set = function(value) 
			self:SaveOptions(frame, "width", value)
			self:UpdateAllFrames()
		end,
	}
end

--- ========================================================= ---
---  Update Height Option
--- ========================================================= ---
function DaHud_Module_Text:UpdateHeightOption(frame)
	DaHud.options.args.textframes.args[frame].args.height = {
		name = L["Height"],
		desc = L["Change the Height."],
		type = 'range',
		min = 0,
		max = 500,
		step = 1,
		bigStep = 20,
		get = function()
			local name, show, framestrata, framelevel, width, height, scale, align, posx, posy, unit, type, style, custom, font, size, outline, monochrome, button, tooltip = unpack(self.db.profile[frame])
			return height
		end,
		set = function(value) 
			self:SaveOptions(frame, "height", value)
			self:UpdateAllFrames()
		end,
	}
end

--- ========================================================= ---
---  Update Scale Option
--- ========================================================= ---
function DaHud_Module_Text:UpdateScaleOption(frame)
	DaHud.options.args.textframes.args[frame].args.scale = {
		name = L["Scale"],
		desc = L["Change the Scale."],
		type = 'range',
		min = 0.25,
		max = 3,
		step = 0.01,
		bigStep = 0.05,
		get = function()
			local name, show, framestrata, framelevel, width, height, scale, align, posx, posy, unit, type, style, custom, font, size, outline, monochrome, button, tooltip = unpack(self.db.profile[frame])
			return scale
		end,
		set = function(value) 
			self:SaveOptions(frame, "scale", value)
			self:UpdateAllFrames()
		end,
	}
end

--- ========================================================= ---
---  Update Align Option
--- ========================================================= ---
function DaHud_Module_Text:UpdateAlignOption(frame)
	DaHud.options.args.textframes.args[frame].args.align = {
		name = L["Text Align"],
		desc = L["Choose which side to Align the Text in the Frame."],
		type = 'text',
		validate = alignValidate,
		validateDesc = alignValidateDesc,
		get = function()
			local name, show, framestrata, framelevel, width, height, scale, align, posx, posy, unit, type, style, custom, font, size, outline, monochrome, button, tooltip = unpack(self.db.profile[frame])
			return align
		end,
		set = function(value) 
			self:SaveOptions(frame, "align", value)
			self:UpdateAllFrames()
		end,
	}
end

--- ========================================================= ---
---  Update POS X Option
--- ========================================================= ---
function DaHud_Module_Text:UpdatePosXOption(frame)
	DaHud.options.args.textframes.args[frame].args.posx = {
		name = L["Pos X"],
		desc = L["Change the X Position."],
		type = 'range',
		min = -500,
		max = 500,
		step = 1,
		bigStep = 20,
		get = function()
			local name, show, framestrata, framelevel, width, height, scale, align, posx, posy, unit, type, style, custom, font, size, outline, monochrome, button, tooltip = unpack(self.db.profile[frame])
			return posx
		end,
		set = function(value) 
			self:SaveOptions(frame, "posx", value)
			self:UpdateAllFrames()
		end,
	}
end

--- ========================================================= ---
---  Update POS Y Option
--- ========================================================= ---
function DaHud_Module_Text:UpdatePosYOption(frame)
	DaHud.options.args.textframes.args[frame].args.posy = {
		name = L["Pos Y"],
		desc = L["Change the Y Position."],
		type = 'range',
		min = -500,
		max = 500,
		step = 1,
		bigStep = 20,
		get = function()
			local name, show, framestrata, framelevel, width, height, scale, align, posx, posy, unit, type, style, custom, font, size, outline, monochrome, button, tooltip = unpack(self.db.profile[frame])
			return posy
		end,
		set = function(value) 
			self:SaveOptions(frame, "posy", value)
			self:UpdateAllFrames()
		end,
	}
end

--- ========================================================= ---
---  Update Unit Option
--- ========================================================= ---
function DaHud_Module_Text:UpdateUnitOption(frame)
	DaHud.options.args.textframes.args[frame].args.unit = {
		name = L["Event Unit"],
		desc = L["Choose which Unit the Event is monitoring and showing."],
		type = 'text',
		validate = eventUnitValidate,
		validateDesc = eventUnitValidateDesc,
		get = function()
			local name, show, framestrata, framelevel, width, height, scale, align, posx, posy, unit, type, style, custom, font, size, outline, monochrome, button, tooltip = unpack(self.db.profile[frame])
			return unit
		end,
		set = function(value) 
			self:SaveOptions(frame, "unit", value)
			self:UpdateAllFrames()
		end,
	}
end

--- ========================================================= ---
---  Update Type Option
--- ========================================================= ---
function DaHud_Module_Text:UpdateTypeOption(frame)
	DaHud.options.args.textframes.args[frame].args.type = {
		name = L["Event Type"],
		desc = L["Choose which Event Type to show."],
		type = 'text',
		validate = eventTypeValidate,
		validateDesc = eventTypeValidateDesc,
		get = function()
			local name, show, framestrata, framelevel, width, height, scale, align, posx, posy, unit, type, style, custom, font, size, outline, monochrome, button, tooltip = unpack(self.db.profile[frame])
			return type
		end,
		set = function(value)
			local style = defaultStyle[value]
			self:SaveOptions(frame, "type", value)
			if style ~= "none" then
				self:SaveOptions(frame, "style", style)
			else
				self:SaveOptions(frame, "style", "")
			end
			if style ~= "none" then
				self:SaveOptions(frame, "custom", textStyles[value][style])
			else
				self:SaveOptions(frame, "custom", "")
			end
			self:UpdateStyleOption(frame)
			self:UpdateAllFrames()
		end,
	}
end

--- ========================================================= ---
---  Update Style Option
--- ========================================================= ---
function DaHud_Module_Text:UpdateStyleOption(frame)
	DaHud.options.args.textframes.args[frame].args.style = {
		name = L["Event Style"],
		desc = L["Choose which Event Style to use."],
		type = 'text',
		validate = self:getStyleValidate(frame),
		validateDesc = self:getStyleValidateDesc(frame),
		get = function()
			local name, show, framestrata, framelevel, width, height, scale, align, posx, posy, unit, type, style, custom, font, size, outline, monochrome, button, tooltip = unpack(self.db.profile[frame])
			return style
		end,
		set = function(value)
			local name, show, framestrata, framelevel, width, height, scale, align, posx, posy, unit, type, style, custom, font, size, outline, monochrome, button, tooltip = unpack(self.db.profile[frame])
			self:SaveOptions(frame, "style", value)
			self:SaveOptions(frame, "custom", textStyles[type][value])
			self:UpdateAllFrames()
		end,
	}
end

--- ========================================================= ---
---  Update Custom Option
--- ========================================================= ---
function DaHud_Module_Text:UpdateCustomOption(frame)
	DaHud.options.args.textframes.args[frame].args.custom = {
		name = L["Custom Event"],
		desc = L["Create a Custom Event for the Gauge to monitor and show."],
		type = "text",
		usage = L["DogTag-1.0 tags. See http://www.wowace.com/wiki/DogTag-1.0"],
		get = function()
			local name, show, framestrata, framelevel, width, height, scale, align, posx, posy, unit, type, style, custom, font, size, outline, monochrome, button, tooltip = unpack(self.db.profile[frame])
			return custom
		end,
		set = function(value) 
			local name, show, framestrata, framelevel, width, height, scale, align, posx, posy, unit, type, style, custom, font, size, outline, monochrome, button, tooltip = unpack(self.db.profile[frame])
			if type == "custom" then
				self:SaveOptions(frame, "custom", value)
				self:UpdateAllFrames()
			end
		end,
	}
end

--- ========================================================= ---
---  Update Font Option
--- ========================================================= ---
function DaHud_Module_Text:UpdateFontOption(frame)
	DaHud.options.args.textframes.args[frame].args.font = {
		name = L["Font Face"],
		desc = L["Set the Font Face for this Text Frame."],
		type = "text",
		validate = fontslist,
		get = function()
			local name, show, framestrata, framelevel, width, height, scale, align, posx, posy, unit, type, style, custom, font, size, outline, monochrome, button, tooltip = unpack(self.db.profile[frame])
			return font
		end,
		set = function(value) 
			self:SaveOptions(frame, "font", value)
			self:UpdateAllFrames()
		end,
	}
end

--- ========================================================= ---
---  Update Size Option
--- ========================================================= ---
function DaHud_Module_Text:UpdateSizeOption(frame)
	DaHud.options.args.textframes.args[frame].args.size = {
		name = L["Font Size"],
		desc = L["Change the Font Size."],
		type = 'range',
		min = 4,
		max = 22,
		step = 1,
		bigStep = 2,
		get = function()
			local name, show, framestrata, framelevel, width, height, scale, align, posx, posy, unit, type, style, custom, font, size, outline, monochrome, button, tooltip = unpack(self.db.profile[frame])
			return size
		end,
		set = function(value) 
			self:SaveOptions(frame, "size", value)
			self:UpdateAllFrames()
		end,
	}
end

--- ========================================================= ---
---  Update Outline Option
--- ========================================================= ---
function DaHud_Module_Text:UpdateOutlineOption(frame)
	DaHud.options.args.textframes.args[frame].args.outline = {
		name = L["Outline Text"],
		desc = L["Choose how to Outline the Text."],
		type = 'text',
		validate = outlineValidate,
		validateDesc = outlineValidateDesc,
		get = function()
			local name, show, framestrata, framelevel, width, height, scale, align, posx, posy, unit, type, style, custom, font, size, outline, monochrome, button, tooltip = unpack(self.db.profile[frame])
			return outline
		end,
		set = function(value) 
			self:SaveOptions(frame, "outline", value)
			self:UpdateAllFrames()
		end,
	}
end

--- ========================================================= ---
---  Update Monochrome Option
--- ========================================================= ---
function DaHud_Module_Text:UpdateMonochromeOption(frame)
	DaHud.options.args.textframes.args[frame].args.monochrome = {
		name = L["Monochrome"],
		desc = L["Monochrome the Text."],
		type = 'toggle',
		get = function()
			local name, show, framestrata, framelevel, width, height, scale, align, posx, posy, unit, type, style, custom, font, size, outline, monochrome, button, tooltip = unpack(self.db.profile[frame])
			return monochrome
		end,
		set = function()
			local name, show, framestrata, framelevel, width, height, scale, align, posx, posy, unit, type, style, custom, font, size, outline, monochrome, button, tooltip = unpack(self.db.profile[frame])
			self:SaveOptions(frame, "monochrome", not(monochrome))
			self:UpdateAllFrames()
		end,
	}
end

--- ========================================================= ---
---  Update Button Option
--- ========================================================= ---
function DaHud_Module_Text:UpdateButtonOption(frame)
	DaHud.options.args.textframes.args[frame].args.button = {
		name = L["Button"],
		desc = L["Enable/Disable Button support on this Frame."],
		type = 'toggle',
		get = function()
			local name, show, framestrata, framelevel, width, height, scale, align, posx, posy, unit, type, style, custom, font, size, outline, monochrome, button, tooltip = unpack(self.db.profile[frame])
			return button
		end,
		set = function()
			local name, show, framestrata, framelevel, width, height, scale, align, posx, posy, unit, type, style, custom, font, size, outline, monochrome, button, tooltip = unpack(self.db.profile[frame])
			self:SaveOptions(frame, "button", not(button))
			self:UpdateAllFrames()
		end,
	}
end

--- ========================================================= ---
---  Update Tooltip Option
--- ========================================================= ---
function DaHud_Module_Text:UpdateTooltipOption(frame)
	DaHud.options.args.textframes.args[frame].args.tooltip = {
		name = L["Tooltip"],
		desc = L["Choose when to show the Tooltip (Only works when Button is enabled)."],
		type = 'text',
		validate = tooltipValidate,
		validateDesc = tooltipValidateDesc,
		get = function()
			local name, show, framestrata, framelevel, width, height, scale, align, posx, posy, unit, type, style, custom, font, size, outline, monochrome, button, tooltip = unpack(self.db.profile[frame])
			return tooltip
		end,
		set = function(value) 
			self:SaveOptions(frame, "tooltip", value)
			self:UpdateAllFrames()
		end,
	}
end

--- ========================================================= ---
---  Update Global Option
--- ========================================================= ---
function DaHud_Module_Text:UpdateGlobalOption()
	DaHud.options.args.textframes.args.global = {
		name = L["Global Options"],
		desc = L["Set all Options Globally."],
		type = 'group',
		order = 1,
		args = {
			font = {
				name = L["Font Face"],
				desc = L["Set the Font Face for this Text Frame."],
				type = "text",
				validate = fontslist,
				get = false,
				set = function(value)
					self:SaveGlobal("font", value)
					self:UpdateAllFrames()
				end,
			},
			size = {
				name = L["Font Size"],
				desc = L["Change the Font Size."],
				type = 'range',
				min = 4,
				max = 22,
				step = 1,
				bigStep = 2,
				get = function(value)
					if value then
						return value
					else
						return 12
					end
				end,
				set = function(value) 
					self:SaveGlobal("size", value)
					self:UpdateAllFrames()
				end,
			},
		},
	}
end

--- ========================================================= ---
---  Save Options
--- ========================================================= ---
function DaHud_Module_Text:SaveGlobal(var, value)
	for i=1, self.db.profile.number do
		local frame = "hudtext"..i
		local name, show, framestrata, framelevel, width, height, scale, align, posx, posy, unit, type, style, custom, font, size, outline, monochrome, button, tooltip = unpack(self.db.profile[frame])
		
		if var == "font" then
			font = value
		elseif var == "size" then
			size = value
		end
				
		self.db.profile[frame] = {name, show, framestrata, framelevel, width, height, scale, align, posx, posy, unit, type, style, custom, font, size, outline, monochrome, button, tooltip}
	end
end

--- ========================================================= ---
---  Save Options
--- ========================================================= ---
function DaHud_Module_Text:SaveOptions(frame, var, value)
	local name, show, framestrata, framelevel, width, height, scale, align, posx, posy, unit, type, style, custom, font, size, outline, monochrome, button, tooltip = unpack(self.db.profile[frame])
	
	if var == "name" then
		name = value
	elseif var == "show" then
		show = value
	elseif var == "framestrata" then
		framestrata = value
	elseif var == "framelevel" then
		framelevel = value
	elseif var == "width" then
		width = value
	elseif var == "height" then
		height = value
	elseif var == "scale" then
		scale = value
	elseif var == "align" then
		align = value
	elseif var == "posx" then
		posx = value
	elseif var == "posy" then
		posy = value
	elseif var == "unit" then
		unit = value
	elseif var == "type" then
		type = value
	elseif var == "style" then
		style = value
	elseif var == "custom" then
		custom = value
	elseif var == "font" then
		font = value
	elseif var == "size" then
		size = value
	elseif var == "outline" then
		outline = value
	elseif var == "monochrome" then
		monochrome = value
	elseif var == "button" then
		button = value
	elseif var == "tooltip" then
		tooltip = value
	end
			
	self.db.profile[frame] = {name, show, framestrata, framelevel, width, height, scale, align, posx, posy, unit, type, style, custom, font, size, outline, monochrome, button, tooltip}
end

--- ========================================================= ---
---  Create Frame
--- ========================================================= ---
function DaHud_Module_Text:CreateFrame(frametype, framename, parent, vals)
	local name, show, framestrata, framelevel, width, height, scale, align, posx, posy, unit, type, style, custom, font, size, outline, monochrome, button, tooltip = unpack(self.db.profile[vals])
	local f = CreateFrame(frametype, framename, parent)

	f:SetWidth(width)
	f:SetHeight(height)
	f:SetScale(scale)
	f:SetPoint(align, parent, "Center", posx, posy)
	f:SetFrameStrata(framestrata)
	f:SetFrameLevel(framelevel)
	
	f.unit = unit
	f.framename = framename
	
	f:SetAttribute("unit", unit)
	f:SetAttribute("shown", "unit")
	f:SetAttribute("useunit", unit)
	RegisterUnitWatch(f)

	local fs = f:CreateFontString(framename.."Text", "ARTWORK")
	local fontfile = Media:Fetch(Media.MediaType.FONT, font)
	if monochrome then
		fs:SetFont(fontfile, size, outline, "MONOCHROME")
	else
		fs:SetFont(fontfile, size, outline)
	end
	local r, g, b, a = unpack(DaHud.db.profile.colors.textshadow)
	fs:SetShadowColor(r, g, b, a)
	fs:SetJustifyH(align)
	fs:SetAllPoints(f)
	
	f:Show()

	return f
end

--- ========================================================= ---
---  Create Text Button
--- ========================================================= ---
function DaHud_Module_Text:CreateTextButton(frametype, framename, parent, vals)
	local name, show, framestrata, framelevel, width, height, scale, align, posx, posy, unit, type, style, custom, font, size, outline, monochrome, button, tooltip = unpack(self.db.profile[vals])
	local f = CreateFrame(frametype, framename, parent, "SecureUnitButtonTemplate")

	f:SetWidth(width)
	f:SetHeight(height)
	f:SetScale(scale)
	f:SetPoint("Center", parent, "Center", posx, posy)
	f:SetFrameLevel(framelevel+1)

	f:RegisterForClicks("AnyUp")
	
	f:SetScript("OnEnter", function(self)
		if self.tt == "always" or (self.tt == "ooc" and not(InCombatLockdown())) then
			GameTooltip:SetOwner(self, "ANCHOR_NONE")
			GameTooltip:SetPoint("BOTTOM", self, "TOP", 0, 20)
			GameTooltip:SetUnit(unit)
			GameTooltip:Show()
		end
	end)
		
	f:SetScript("OnLeave", function(self) 
		if(GameTooltip:IsOwned(self)) then
			GameTooltip:Hide()
		end
	end)
	
	f:SetScript("OnEvent", function(self)
	
	end)

	f.tt = tooltip
	f.unit = unit
	f:SetAttribute("*type1", "target")
	f:SetAttribute("*type2", "menu")
	f:SetAttribute("unit", unit)
	f:SetAttribute("shown", "unit")
	f:SetAttribute("useunit", unit)
	
	if unit == "player" then
		f.menu = function(self)
			ToggleDropDownMenu(1, nil, PlayerFrameDropDown, "cursor", 0, 0)
		end
	elseif unit == "target" then
		f.menu = function(self)
			ToggleDropDownMenu(1, nil, TargetFrameDropDown, "cursor", 0, 0)
		end
	elseif unit == "focus" then
		f.menu = function(self)
			ToggleDropDownMenu(1, nil, FocusFrameDropDown, "cursor", 0, 0)
		end
	elseif unit == "pet" then
		f.menu = function(self)
			ToggleDropDownMenu(1, nil, PetFrameDropDown, "cursor", 0, 0)
		end
	end
	
	RegisterUnitWatch(f)
	
	ClickCastFrames = ClickCastFrames or {}
	ClickCastFrames[f] = true
	
	f:Show()

	f:Show()
end

--- ========================================================= ---
---  Create Frames
--- ========================================================= ---
function DaHud_Module_Text:CreateFrames()
	for i=1, self.db.profile.number do
		self:CreateFrame("Frame", "DaHudTextFrame"..i, getglobal("DaHudFrame"), "hudtext"..i)
		self:CreateTextButton("Button", "DaHudTextFrame"..i.."Button", getglobal("DaHudFrame"), "hudtext"..i)
	end
end

--- ========================================================= ---
---  Update All Frames
--- ========================================================= ---
function DaHud_Module_Text:UpdateAllFrames()
	for i=1, self.db.profile.number do
		self:UpdateFrame("DaHudTextFrame"..i, "hudtext"..i)
		self:UpdateButton("DaHudTextFrame"..i, "hudtext"..i)
	end
end

--- ========================================================= ---
---  Update Frame
--- ========================================================= ---
function DaHud_Module_Text:UpdateFrame(framename, vals)
	local name, show, framestrata, framelevel, width, height, scale, align, posx, posy, unit, type, style, custom, font, size, outline, monochrome, button, tooltip = unpack(self.db.profile[vals])
	local f = getglobal(framename)
	local fs = getglobal(framename.."Text")

	if DaHud_ConfigMode then
		unit = "player"
	end

	f:SetWidth(width)
	f:SetHeight(height)
	f:SetScale(scale)
	f:ClearAllPoints()
	f:SetPoint(align, getglobal("DaHudFrame"), "Center", posx, posy)
	f:SetFrameStrata(framestrata)
	f:SetFrameLevel(framelevel)
	
	f.unit = unit
	f.framename = framename
	
	f:SetAttribute("unit", unit)
	f:SetAttribute("shown", "unit")
	f:SetAttribute("useunit", unit)
	
	local fontfile = Media:Fetch(Media.MediaType.FONT, font)
	if monochrome then
		fs:SetFont(fontfile, size, outline, "MONOCHROME")
	else
		fs:SetFont(fontfile, size, outline)
	end
	local r, g, b, a = unpack(DaHud.db.profile.colors.textshadow)
	fs:SetShadowColor(r, g, b, a)
	fs:SetJustifyH(align)
	fs:SetAllPoints(f)
	
	if show then
		RegisterUnitWatch(f)
	else
		UnregisterUnitWatch(f)
		f:Hide()
	end	
end

--- ========================================================= ---
---  Update Button
--- ========================================================= ---
function DaHud_Module_Text:UpdateButton(framename, vals)
	local name, show, framestrata, framelevel, width, height, scale, align, posx, posy, unit, type, style, custom, font, size, outline, monochrome, button, tooltip = unpack(self.db.profile[vals])
	local f = getglobal(framename.."Button")
	
	if DaHud_ConfigMode then
		unit = "player"
	end
	
	f:SetWidth(width)
	f:SetHeight(height)
	f:SetScale(scale)
	f:SetPoint("Center", getglobal("DaHudFrame"), "Center", posx, posy)
	f:SetFrameLevel(framelevel+1)
	
	f.tt = tooltip
	f.unit = unit
	
	f:SetAttribute("*type1", "target")
	f:SetAttribute("*type2", "menu")
	f:SetAttribute("unit", unit)
	f:SetAttribute("shown", "unit")
	f:SetAttribute("useunit", unit)
	
	if unit == "player" then
		f.menu = function(self)
			ToggleDropDownMenu(1, nil, PlayerFrameDropDown, "cursor", 0, 0)
		end
	elseif unit == "target" then
		f.menu = function(self)
			ToggleDropDownMenu(1, nil, TargetFrameDropDown, "cursor", 0, 0)
		end
	elseif unit == "focus" then
		f.menu = function(self)
			ToggleDropDownMenu(1, nil, FocusFrameDropDown, "cursor", 0, 0)
		end
	elseif unit == "pet" then
		f.menu = function(self)
			ToggleDropDownMenu(1, nil, PetFrameDropDown, "cursor", 0, 0)
		end
	end
	
	if button then
		RegisterUnitWatch(f)
		ClickCastFrames = ClickCastFrames or {}
		ClickCastFrames[f] = true
	else
		UnregisterUnitWatch(f)
		ClickCastFrames = ClickCastFrames or {}
		ClickCastFrames[f] = nil
		f:Hide()
	end
end

--- ========================================================= ---
---  Process All Frames
--- ========================================================= ---
function DaHud_Module_Text:ProcessAllFrames()
	for i=1, self.db.profile.number do
		self:ProcessFrame("DaHudTextFrame"..i, "hudtext"..i)
	end
end

--- ========================================================= ---
---  Process Frame
--- ========================================================= ---
function DaHud_Module_Text:ProcessFrame(framename, vals)
	local name, show, framestrata, framelevel, width, height, scale, align, posx, posy, unit, type, style, custom, font, size, outline, monochrome, button, tooltip = unpack(self.db.profile[vals])
	local result, spell, rank, displayName, icon, startTime, endTime
	local f = getglobal(framename)
	local fs = getglobal(framename.."Text")

	if DaHud_ConfigMode then
		unit = "player"
	end

	if type ~= "casting" and type ~= "sunders" then
		if DogTag:Evaluate(unit, custom) then
			result = DogTag:Evaluate(unit, custom)
		end
	elseif type == "sunders" then
		for i = 1,40  do
			local name, rank, texture, count, debuffType, duration, timeLeft  =  UnitDebuff(unit, i)
			if(name == "Sunder Armor") then
				result = count
				break
			end
		end
	elseif type == "casting" then
		spell, rank, displayName, icon, startTime, endTime = UnitCastingInfo(unit)
		if spell then
			f.type = "cast"
			f.spell = spell
			f.rank = rank
			f.displayName = displayName
			f.icon = icon
			f.startTime = startTime
			f.endTime = endTime
		else
			spell, rank, displayName, icon, startTime, endTime = UnitChannelInfo(unit)
			if spell then
				f.type = "channel"
				f.spell = spell
				f.rank = rank
				f.displayName = displayName
				f.icon = icon
				f.startTime = startTime
				f.endTime = endTime
			else
				f.type = nil
				f.spell = nil
				f.rank = rank
				f.displayName = nil
				f.icon = nil
				f.startTime = nil
				f.endTime = nil
			end
		end
		if f.spell then
			if string.find(f.rank, "Rank") then
				local timeleft = self:FormatTime((f.endTime/1000) - GetTime())
				result = f.spell.." ("..f.rank..") "..timeleft
			else
				local timeleft = self:FormatTime((f.endTime/1000) - GetTime())
				result = f.spell.." "..timeleft
			end
		else
			result = nil
		end
	end
	
	if DaHud_ConfigMode and type == "casting" then
		result = "Castingbar Text Here"
	end
	
	if DaHud_ConfigMode and type == "combos" then
		result = "5"
	end
	
	if DaHud_ConfigMode and type == "sunders" then
		result = "5"
	end

	fs:SetText(result)
end